<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends BaseController {
    public function index(){
        layout(false);
        $this->display();
    }
    public function login(){
        //var_dump($_POST);
        $user['username']=I('post.username');//$_POST['username'];I方法接收数据（安全问题）
        $user['password']=I('post.password');//$_POST['password'];
        $list=M('users');
        $result=$list->where($user)->select();
        //var_dump($result);
        if(count($result)>0){
            //登录成功后跳转后台页面
            //设置登录状态
            $result[0]['username']=html_entity_decode($result[0]['username']);//将i方法接收的html字符串转换成html代码
            cookie('username',$result[0]['username'],3600);
            redirect(U('Index/index'));
        } else {
            //错误返回登录页
            redirect(U('Login/index'));
    
        }
    }
    public function loginOut(){
        // 退出登录
        cookie('username',null);
        redirect(U('Index/index'),  '');
    }
    public function register(){
        $this->display();
    }
}